﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CPPEI.PM.Shell.Dialogs
{
    /// <summary>
    /// Interaction logic for CreateWorkSheetDlg.xaml
    /// </summary>
    public partial class CreateWorkSheetDlg : Window
    {
        public CreateWorkSheetDlg()
        {
            InitializeComponent();

            for (int index = 0; index < UIContext.Instance.Project.WorkItemCategoryList.Count; index++)
            {
                RadioButton radioButton = new RadioButton();
                radioButton.Content = UIContext.Instance.Project.WorkItemCategoryList[index].Caption;

                TreeViewItem treeViewItem = new TreeViewItem();
                treeViewItem.Header = radioButton;

                radioButton.DataContext = UIContext.Instance.Project.WorkItemCategoryList[index];

                _ctlTreeView.Items.Add(treeViewItem);
            }
        }

        private void _ctlBtnCreate_Click_1(object sender, RoutedEventArgs e)
        {
            WorkItemCategory selWorkItemCategory = null;

            for (int index = 0; index < _ctlTreeView.Items.Count; index++)
            {
                TreeViewItem treeViewItem = _ctlTreeView.Items[index] as TreeViewItem;

                RadioButton radioButton = treeViewItem.Header as RadioButton;
                if (radioButton.IsChecked == true)
                {
                    selWorkItemCategory = radioButton.DataContext as WorkItemCategory;
                    break;
                }
            }
            if (selWorkItemCategory != null)
            {
                new PMServiceRef.PMWebServiceSoapClient().CreateWorkSheet(UIContext.Instance.Account, UIContext.Instance.Project.Id, this._ctlEditCaption.Text, selWorkItemCategory.Id);
                DialogResult = true;
            }
        }
    }
}
